/**
 * Alibaba.com.cn Inc.
 * Copyright (c) 2004-2021 All Rights Reserved.
 */
package com.smart.controller;

import com.smart.common.PageInfo;
import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.smart.model.request.UserIdentificationEquBindRequest;
import com.smart.model.request.UserIdentificationPageRequest;
import com.smart.model.request.UserIdentificationRequest;
import com.smart.model.vo.ProjectUseControlVO;
import com.smart.model.vo.UserIdentificationPageVO;
import com.smart.model.vo.UserIdentificationVO;
import com.smart.service.UserIdentificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @author zhanghong
 * @version UserIdentificationController.java, v 0.1 2023/7/4 10:54 下午 UserIdentificationController Exp $$
 */
@RestController
@RequestMapping("/identification")
@Api(value = "人证机识别模块", tags = {"人证机识别模块"})
public class UserIdentificationController {

    @Autowired
    private UserIdentificationService userIdentificationService;

    @ApiOperation("【机器端】新增识别人员信息")
    @PostMapping("/record")
    public WebResponse<Boolean> add(@Valid @RequestBody UserIdentificationRequest request) {
        return WebResponse.build(userIdentificationService.record(request));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "【服务端】根据设备编号查询最新一条识别数据", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get/{equNo}")
    public WebResponse<UserIdentificationVO> getByKey(@PathVariable("equNo") String equNo) {
        return WebResponse.build(userIdentificationService.getByEquNo(equNo));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "【云服务端】清空设备的所有识别信息", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/clear/{equNo}")
    public WebResponse<Boolean> clearEquNo(@PathVariable("equNo") String equNo) {
        return WebResponse.build(userIdentificationService.clearEquNo(equNo));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "【运营端】分页查询人证设备管理", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<UserIdentificationPageVO>> pageQuery(@RequestBody UserIdentificationPageRequest request) {
        return WebResponse.build(userIdentificationService.pageQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "【运营端】查询单条设备管理信息", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/getEquMangeInfo/{projectId}")
    public WebResponse<UserIdentificationPageVO> getEquMangeInfoByProjectId(@PathVariable("projectId") Long projectId) {
        return WebResponse.build(userIdentificationService.getEquMangeInfoByProjectId(projectId));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "【运营端】编辑保存绑定设备信息", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/saveEquInfo")
    public WebResponse<Boolean> saveEquInfo(@RequestBody UserIdentificationEquBindRequest request) {
        return WebResponse.build(userIdentificationService.saveEquInfo(request));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "【服务端】查询项目开通情况和设备列表", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/getOpenInfo")
    public WebResponse<ProjectUseControlVO> getOpenInfo() {
        return WebResponse.build(userIdentificationService.getOpenInfo());
    }
}
